root_user = {"root": "root"}
common_user = {"hd": "666"}
user_info = {"root": {"name": "swy", "sex": "m", "age": "20", "hobby": "computer"}, "hd": {"name": "哈登", "sex": "m", "age":"28", "bobby": "后撤步"}}


# 登录操作
def enter():
    global user_name, pwd
    user_name = input("请输入用户名：")
    pwd = input("请输入密码：")
    if user_name in root_user and pwd in root_user.values():
        return menu2()
    elif user_name in common_user and pwd in common_user.values():
        return menu3()
    else:
        print("输入用户和密码错误或不存在，请重新输入！")
        return enter()


# 注册操作
def register():
    user_name = input("请输入需要注册用户名：")
    pwd = input("请输入注册密码：")
    common_user.update({user_name: pwd})
    print("注册成功，请编辑信息！")
    name = input("姓名：")
    sex = input("性别：")
    age = input("年龄：")
    hobby = input("爱好:")
    user_info.update({user_name: {"name": name, "sex": sex, "age": age, "hobby": hobby}})
    print("注册成功！")
    print("".center(52,"-"))
    return menu1()


# 超级用户查看所有用户信息
def view_userinfo():
    for i, j in user_info.items():
        print(f"用户名：{i}  用户信息：{j}")
    enter = input("按任意键返回菜单")
    return menu2()


# 超级用户修改信息
def mod_userinfo():
    user_name2 = input("请输入需要修改的用户名：")
    if user_name2 in user_info.keys():
        print("用户名：", user_name2)
        n = 0
        for i, j in user_info[user_name2].items():
            n += 1
            print(f"{n}.{i}：{j} ")
        print("5.退出修改")
        while (True):
            option = input("请输入你要修改的选项：")
            if option == "1":
                info = input("请输入你要修改的内容：")
                user_info[user_name2]["name"] = info
            elif option == "2":
                info = input("请输入你要修改的内容：")
                user_info[user_name2]["sex"] = info
            elif option == "3":
                info = input("请输入你要修改的内容：")
                user_info[user_name2]["age"] = info
            elif option == "4":
                info = input("请输入你要修改的内容：")
                user_info[user_name2]["hobby"] = info
            elif option == "5":
                print("退出修改")
                break
            else:
                print("输入不正确，请重新输入")
        print("修改成功！")
        print("".center(52,"-"))
    else:
        print("输入用户不存在")
    return menu2()


# 超级用户添加用户
def add_user():
    user_name3 = input("请输入需要添加的用户名：")
    pwd3 = input("请输入添加用户的密码：")
    common_user.update({user_name3: pwd3})
    print("添加成功，请编辑信息！")
    name = input("姓名：")
    sex = input("性别：")
    age = input("年龄：")
    hobby = input("爱好:")
    user_info.update({user_name3: {"name": name, "sex": sex, "age": age, "hobby": hobby}})
    print("添加成功！")
    print("".center(52, "-"))
    return menu2()


# 超级用户删除用户
def delate_user():
    print("".center(52,"-"))
    user_name4 = input("请输入要删除的用户名：")
    common_user.pop(user_name4)
    user_info.pop(user_name4)
    print("删除成功！")
    return menu2()


# 超级用户菜单
def menu2():
    print("超级用户菜单".center(50,"-"))
    print("1.查看用户信息")
    print("2.修改用户信息")
    print("3.增加用户")
    print("4.删除用户")
    print("5.返回主菜单")
    print("6.退出")
    print("".center(50,"-"))
    option2 = input("请输入你要执行的操作：")
    if option2 == "1":
        return view_userinfo()
    elif option2 == "2":
        return mod_userinfo()
    elif option2 == "3":
        return add_user()
    elif option2 == "4":
        return delate_user()
    elif option2 == "5":
        return menu1()
    elif option2 == "6":
        print("退出")
    else:
        print("输入不正确，请重新输入！")
        return menu2()


# 普通用户查看个人信息
def view():
    print("用户名：", user_name)
    n = 0
    for i, j in user_info[user_name].items():
        n += 1
        print(f"{n}.{i}：{j} ")
    enter = input("按任意键返回菜单")
    return menu3()


# 普通用户修改个人信息
def mod():
    print("用户名：", user_name)
    n = 0
    for i, j in user_info[user_name].items():
        n += 1
        print(f"{n}.{i}：{j} ")
    print("5.退出修改")
    while (True):
        option = input("请输入你要修改的选项：")
        if option == "1":
            info = input("请输入你要修改的内容：")
            user_info[user_name]["name"] = info
        elif option == "2":
            info = input("请输入你要修改的内容：")
            user_info[user_name]["sex"] = info
        elif option == "3":
            info = input("请输入你要修改的内容：")
            user_info[user_name]["age"] = info
        elif option == "4":
            info = input("请输入你要修改的内容：")
            user_info[user_name]["hobby"] = info
        elif option == "5":
            print("退出修改")
            break
        else:
            print("输入不正确，请重新输入")
    print("修改成功！")
    print("".center(52,"-"))
    return menu3()


# 普通用户菜单
def menu3():
    print("普通用户菜单".center(50, "-"))
    print("1.查看个人信息")
    print("2.修改个人信息")
    print("3.返回主菜单")
    print("4.退出")
    print("".center(52,"-"))
    option3 = input("请输入你要执行的操作：")
    if option3 == "1":
        return view()
    elif option3 == "2":
        return mod()
    elif option3 == "3":
        return menu1()
    elif option3 == "4":
        print("退出！")
    else:
        print("输入不正确，请重新输入！")
        return menu3()


# 主菜单
def menu1():
    print("主菜单".center(50, "-"))
    print("1.登录")
    print("2.注册")
    print("3.退出")
    print("".center(52, "-"))
    option1 = input("请输入你要执行的操作：")
    if option1 == "1":
        return enter()
    elif option1 == "2":
        return register()
    elif option1 == "3":
        print("退出")
    else:
        print("输入不正确，请重新输入！")
        return menu1()


menu1()
